<?php # SingleHotelSearch.php
require "hotels.class.php";
require "hotelcharacteristics.class.php";
require "address.class.php";
require "country.class.php";
require "star_ratings.class.php";

/*
 * Specify the field names that are in the form.
 */
$allowedFields = array(
 			'hotelId',
			'search'
);

/*
 * Specify the field names that are required...
 */
$requiredFields = array(
			'hotelId'
);

$error = false;
$message = array();
foreach($_GET AS $key => $value)
{
	// first make sure this is an allowed field
	if(in_array($key, $allowedFields))
	{
		$$key = $value;
		
		// is this a required field?
		if(in_array($key, $requiredFields) && $value == '')
		{
			$error = true;
			$message = '<error>The field '.$key.' is required.</error>';
		}
	}
	else
	{
		$error = true;
		$message = '<error>The field '.$key.' does not exist.</error>';
	}
}

$hotelId = '';
if (!$error) {
	if (isset($_GET['hotelId'])){
		$hotelId = $_GET['hotelId'];
	}
	$hotel = Hotels::loadUnique($hotelId);
	$hotel_array = array();
	$characteristic_array = array();
	$hotel_characteristic_array = array();
	$return_arr = array();
	
	$hotelId = $hotel->getHotelId();
	$hotelName = $hotel->getHotelName();
	$hotelURL = $hotel->getHotelURL();
	$address = $hotel->getAddress();
	$country = $hotel->getCountry();
	$starRating = $hotel->getStarRatings();
		
	$hotel_array['hotel_id'] = $hotelId;
	$hotel_array['hotel_name'] = $hotelName;
	$hotel_array['hotel_URL'] = $hotelURL;
	$hotel_array['address_id'] = $address->getAddressId();
	$hotel_array['street_address'] = $address->getStreet();
	$hotel_array['city'] = $address->getCity();
	$hotel_array['state'] = $address->getStateOrProvince();
	$hotel_array['zip'] = $address->getPostalCode();
	$hotel_array['country_code'] = $country->getCountryCode();
	$hotel_array['country_name'] = $country->getCountryName();
	$hotel_array['country_currency'] = $country->getCountryCurrency();
	$hotel_array['star_rating_id'] = $starRating->getStarRatingId();
	$hotel_array['star_rating_code'] = $starRating->getStarRatingCode();
	$hotel_array['star_rating_description'] = $starRating->getStarRatingDescription();
	array_push($return_arr, $hotel_array);
	
	
	$hotelCharacteristics = $hotel->getHotelcharacteristicss();
	$count = count($hotelCharacteristics);
	for ($i = 0; $i < $count; $i++) {
		$characteristic = $hotelCharacteristics[$i]->getCharacteristics();
		$characterisitic_array['characteristicId'] = $characteristic->getCharacteristicId();
		$characteristic_array['characteristicCode'] = $characteristic->getCharacteristicCode();
		$characteristic_array['characteristicDescription'] = $characteristic->getCharacteristicDescription();
		array_push($hotel_characteristic_array, $characteristic_array);
	}
	
	if($count > 0) {
		array_push($return_arr, $hotel_characteristic_array);
	}
	
	print json_encode($return_arr);
}
else {
	$error = true;
	print json_encode($message);
}
?>
